{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 6: Performing String Manipulations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Filtering rows based on conditions "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>reviewId</th><th>userName</th><th>userImage</th><th>content</th><th>score</th><th>thumbsUpCount</th><th>reviewCreatedVersion</th><th>at</th><th>replyContent</th><th>repliedAt</th><th>sortOrder</th><th>appId</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;gp:AOqpTOEhZuqSqqWnaKRgv-9ABYdajFUB0WugPGh-SG-fgH355YH_t7J2q4xYo6ZzN3Mc7iSrrTV6ke8hG_fl4Q&quot;</td><td>&quot;Eric Tie&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14GiGET2XHTvsSEsA07ZBPu2s1E6fOXd9WyT_ahChpw&quot;</td><td>&quot;I cannot open the app anymore&quot;</td><td>1</td><td>0</td><td>&quot;5.4.0.6&quot;</td><td>&quot;2020-10-27 21:24:41&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOH0WP4IQKBZ2LrdNmFy_YmpPCVrV3diEU9KGm3fAX6VG0NAZCudCQpQRRI3GLL_tr8DQzUTP1hrOYG74A&quot;</td><td>&quot;john alpha&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14GjpfgjOEbD3brypMeMT3KvhYlWG_nO2bMnMIfY9&quot;</td><td>&quot;I have been begging for a refund from this app for over a month and nobody is replying me&quot;</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 14:03:28&quot;</td><td>&quot;Please note that from checking our records, your email has been answered, and there was no subscrip…</td><td>&quot;2020-10-27 15:05:52&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOEMCkJB8Iq1p-r9dPwnSYadA5BkPWTf32Z1azuuTvqA9KWdTQqNNXWZsJEhmSuYUY_LmL-OdUIl4j70wg&quot;</td><td>&quot;Sudhakar .S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14GidHUHTvHZTXBX36CdxFeccVR2IasC1MHUHXLuFpg&quot;</td><td>&quot;Very costly for the premium version (approx Indian Rupees 910 per year). Better to download the pre…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 08:18:40&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOGFrUWuKGycpje8kszj3uwHN6tU_fd4gLVFy9z7hfGM7Gan22TJrN89NmGVEdj5o4U6W4I6slbTx8OsQw&quot;</td><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-75aK0WFniac/AAAAAAAAAAI/AAAAAAAAAAA/AMZuucn_nhfTJ2FT63nZ53fe…</td><td>&quot;Used to keep me organized, but all the 2020 UPDATES have made a mess of things !!! Y cudn&#x27;t u leave…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-26 13:28:07&quot;</td><td>&quot;What do you find troublesome about the update? We&#x27;d love to get your feedback, by writing to us at …</td><td>&quot;2020-10-26 14:58:29&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOHls7DW8wmDFzTkHwxuqFkdNQtKHmO6Pt9jhZEQ0Q2rDzcc9WMABIXZNu0pIJOhiFrA4uhMOLq1ZIWKQA&quot;</td><td>&quot;Louann Stoker&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-pBcY_Z-qfB4/AAAAAAAAAAI/AAAAAAAAAAA/AMZuuclb31oz9DIIm_ibRaVH…</td><td>&quot;Dan Birthday Oct 28&quot;</td><td>1</td><td>0</td><td>&quot;5.6.0.7&quot;</td><td>&quot;2020-10-26 06:10:50&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌───────────┬───────────┬───────────┬───────────┬───┬───────────┬───────────┬───────────┬──────────┐\n",
       "│ reviewId  ┆ userName  ┆ userImage ┆ content   ┆ … ┆ replyCont ┆ repliedAt ┆ sortOrder ┆ appId    │\n",
       "│ ---       ┆ ---       ┆ ---       ┆ ---       ┆   ┆ ent       ┆ ---       ┆ ---       ┆ ---      │\n",
       "│ str       ┆ str       ┆ str       ┆ str       ┆   ┆ ---       ┆ str       ┆ str       ┆ str      │\n",
       "│           ┆           ┆           ┆           ┆   ┆ str       ┆           ┆           ┆          │\n",
       "╞═══════════╪═══════════╪═══════════╪═══════════╪═══╪═══════════╪═══════════╪═══════════╪══════════╡\n",
       "│ gp:AOqpTO ┆ Eric Tie  ┆ https://p ┆ I cannot  ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EhZuqSqqW ┆           ┆ lay-lh.go ┆ open the  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ naKRgv-9A ┆           ┆ ogleuserc ┆ app       ┆   ┆           ┆           ┆           ┆          │\n",
       "│ BYdajFUB0 ┆           ┆ ontent.co ┆ anymore   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WugPGh-SG ┆           ┆ m/a-/AOh1 ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ -fgH355YH ┆           ┆ 4GiGET2XH ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ _t7J2q4xY ┆           ┆ TvsSEsA07 ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ o6ZzN3Mc7 ┆           ┆ ZBPu2s1E6 ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ iSrrTV6ke ┆           ┆ fOXd9WyT_ ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ 8hG_fl4Q  ┆           ┆ ahChpw    ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ john      ┆ https://p ┆ I have    ┆ … ┆ Please    ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ H0WP4IQKB ┆ alpha     ┆ lay-lh.go ┆ been      ┆   ┆ note that ┆ 7         ┆           ┆ o        │\n",
       "│ Z2LrdNmFy ┆           ┆ ogleuserc ┆ begging   ┆   ┆ from      ┆ 15:05:52  ┆           ┆          │\n",
       "│ _YmpPCVrV ┆           ┆ ontent.co ┆ for a     ┆   ┆ checking  ┆           ┆           ┆          │\n",
       "│ 3diEU9KGm ┆           ┆ m/a-/AOh1 ┆ refund    ┆   ┆ our       ┆           ┆           ┆          │\n",
       "│ 3fAX6VG0N ┆           ┆ 4GjpfgjOE ┆ from this ┆   ┆ records,  ┆           ┆           ┆          │\n",
       "│ AZCudCQpQ ┆           ┆ bD3brypMe ┆ app for   ┆   ┆ your      ┆           ┆           ┆          │\n",
       "│ RRI3GLL_t ┆           ┆ MT3KvhYlW ┆ over a    ┆   ┆ email has ┆           ┆           ┆          │\n",
       "│ r8DQzUTP1 ┆           ┆ G_nO2bMnM ┆ month and ┆   ┆ been      ┆           ┆           ┆          │\n",
       "│ hrOYG74A  ┆           ┆ IfY9      ┆ nobody is ┆   ┆ answered, ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ replying  ┆   ┆ and there ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ me        ┆   ┆ was no    ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆           ┆   ┆ subscript ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆           ┆   ┆ …         ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Sudhakar  ┆ https://p ┆ Very      ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EMCkJB8Iq ┆ .S        ┆ lay-lh.go ┆ costly    ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ 1p-r9dPwn ┆           ┆ ogleuserc ┆ for the   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ SYadA5BkP ┆           ┆ ontent.co ┆ premium   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WTf32Z1az ┆           ┆ m/a-/AOh1 ┆ version   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ uuTvqA9KW ┆           ┆ 4GidHUHTv ┆ (approx   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ dTQqNNXWZ ┆           ┆ HZTXBX36C ┆ Indian    ┆   ┆           ┆           ┆           ┆          │\n",
       "│ sJEhmSuYU ┆           ┆ dxFeccVR2 ┆ Rupees    ┆   ┆           ┆           ┆           ┆          │\n",
       "│ Y_LmL-OdU ┆           ┆ IasC1MHUH ┆ 910 per   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ Il4j70wg  ┆           ┆ XLuFpg    ┆ year).    ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ Better to ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ download  ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ the prem… ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ SKGflorid ┆ https://p ┆ Used to   ┆ … ┆ What do   ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ GFrUWuKGy ┆ a@bellsou ┆ lay-lh.go ┆ keep me   ┆   ┆ you find  ┆ 6         ┆           ┆ o        │\n",
       "│ cpje8kszj ┆ th.net    ┆ ogleuserc ┆ organized ┆   ┆ troubleso ┆ 14:58:29  ┆           ┆          │\n",
       "│ 3uwHN6tU_ ┆ DAVID S   ┆ ontent.co ┆ , but all ┆   ┆ me about  ┆           ┆           ┆          │\n",
       "│ fd4gLVFy9 ┆           ┆ m/-75aK0W ┆ the 2020  ┆   ┆ the       ┆           ┆           ┆          │\n",
       "│ z7hfGM7Ga ┆           ┆ Fniac/AAA ┆ UPDATES   ┆   ┆ update?   ┆           ┆           ┆          │\n",
       "│ n22TJrN89 ┆           ┆ AAAAAAAI/ ┆ have made ┆   ┆ We'd love ┆           ┆           ┆          │\n",
       "│ NmGVEdj5o ┆           ┆ AAAAAAAAA ┆ a mess of ┆   ┆ to get    ┆           ┆           ┆          │\n",
       "│ 4U6W4I6sl ┆           ┆ AA/AMZuuc ┆ things    ┆   ┆ your      ┆           ┆           ┆          │\n",
       "│ bTx8OsQw  ┆           ┆ n_nhfTJ2F ┆ !!! Y     ┆   ┆ feedback, ┆           ┆           ┆          │\n",
       "│           ┆           ┆ T63nZ53fe ┆ cudn't u  ┆   ┆ by        ┆           ┆           ┆          │\n",
       "│           ┆           ┆ I…        ┆ leave …   ┆   ┆ writing   ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆           ┆   ┆ to us at  ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆           ┆   ┆ h…        ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Louann    ┆ https://p ┆ Dan       ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ Hls7DW8wm ┆ Stoker    ┆ lay-lh.go ┆ Birthday  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ DFzTkHwxu ┆           ┆ ogleuserc ┆ Oct 28    ┆   ┆           ┆           ┆           ┆          │\n",
       "│ qFkdNQtKH ┆           ┆ ontent.co ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ mO6Pt9jhZ ┆           ┆ m/-pBcY_Z ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ EQ0Q2rDzc ┆           ┆ -qfB4/AAA ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ c9WMABIXZ ┆           ┆ AAAAAAAI/ ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ Nu0pIJOhi ┆           ┆ AAAAAAAAA ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ FrA4uhMOL ┆           ┆ AA/AMZuuc ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ q1ZIWKQA  ┆           ┆ lb31oz9DI ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆ Im_ibRaVH ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆ 8…        ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.read_csv('../data/google_store_reviews.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "# pl.Config.set_fmt_str_lengths=50  # for .py scripts\n",
    "import os\n",
    "os.environ['POLARS_FMT_STR_LEN'] = str(50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 1)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;Very costly for the premium version (approx India…</td></tr><tr><td>&quot;Very bad&quot;</td></tr><tr><td>&quot;Very bad&quot;</td></tr><tr><td>&quot;Very slow app it took me 10 min just to start the…</td></tr><tr><td>&quot;Very average app, not intuitive . Will probably s…</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 1)\n",
       "┌─────────────────────────────────────────────────────┐\n",
       "│ content                                             │\n",
       "│ ---                                                 │\n",
       "│ str                                                 │\n",
       "╞═════════════════════════════════════════════════════╡\n",
       "│ Very costly for the premium version (approx Indian… │\n",
       "│ Very bad                                            │\n",
       "│ Very bad                                            │\n",
       "│ Very slow app it took me 10 min just to start the … │\n",
       "│ Very average app, not intuitive . Will probably sp… │\n",
       "└─────────────────────────────────────────────────────┘"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    df\n",
    "    .filter(pl.col('content').str.starts_with('Very'))\n",
    "    .select('content')\n",
    "    .head()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 1)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>userName</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;James Smith&quot;</td></tr><tr><td>&quot;J Smith&quot;</td></tr><tr><td>&quot;Fj Smith&quot;</td></tr><tr><td>&quot;Martyn Smith&quot;</td></tr><tr><td>&quot;D Smith&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 1)\n",
       "┌──────────────┐\n",
       "│ userName     │\n",
       "│ ---          │\n",
       "│ str          │\n",
       "╞══════════════╡\n",
       "│ James Smith  │\n",
       "│ J Smith      │\n",
       "│ Fj Smith     │\n",
       "│ Martyn Smith │\n",
       "│ D Smith      │\n",
       "└──────────────┘"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    df\n",
    "    .filter(pl.col('userName').str.ends_with('Smith'))\n",
    "    .select('userName')\n",
    "    .head()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 1)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;I love this app, but I do have one major gripe - …</td></tr><tr><td>&quot;Not happy, app just asked me to &#x27;sign in&#x27; and now…</td></tr><tr><td>&quot;Will be happy if this app comes with time duratio…</td></tr><tr><td>&quot;V usefull app i love it v much I use it daily wor…</td></tr><tr><td>&quot;I was super happy to download this app but that I…</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 1)\n",
       "┌─────────────────────────────────────────────────────┐\n",
       "│ content                                             │\n",
       "│ ---                                                 │\n",
       "│ str                                                 │\n",
       "╞═════════════════════════════════════════════════════╡\n",
       "│ I love this app, but I do have one major gripe - I… │\n",
       "│ Not happy, app just asked me to 'sign in' and now … │\n",
       "│ Will be happy if this app comes with time duration… │\n",
       "│ V usefull app i love it v much I use it daily work… │\n",
       "│ I was super happy to download this app but that I … │\n",
       "└─────────────────────────────────────────────────────┘"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    df\n",
    "    .filter(pl.col('content').str.contains('happy', literal=True))\n",
    "    .select('content')\n",
    "    .head()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 1)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;I love this app, but I do have one major gripe - …</td></tr><tr><td>&quot;Why are random items popping up on our Grocery Li…</td></tr><tr><td>&quot;I love using this app however when I installed it…</td></tr><tr><td>&quot;There are certain things I love like the fact tha…</td></tr><tr><td>&quot;I love this app, but recently the app keeps crash…</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 1)\n",
       "┌─────────────────────────────────────────────────────┐\n",
       "│ content                                             │\n",
       "│ ---                                                 │\n",
       "│ str                                                 │\n",
       "╞═════════════════════════════════════════════════════╡\n",
       "│ I love this app, but I do have one major gripe - I… │\n",
       "│ Why are random items popping up on our Grocery Lis… │\n",
       "│ I love using this app however when I installed it … │\n",
       "│ There are certain things I love like the fact that… │\n",
       "│ I love this app, but recently the app keeps crashi… │\n",
       "└─────────────────────────────────────────────────────┘"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    df\n",
    "    .filter(pl.col('content').str.contains(r'very happy|best app|I love'))\n",
    "    .select('content')\n",
    "    .head()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1237"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    df\n",
    "    .filter(pl.col('content').str.contains_any(['happy', 'love', 'best']))\n",
    "    .height\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There is more"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 1)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;I love it :D I met great and fun people and this …</td></tr><tr><td>&quot;I love Habitica! I&#x27;ve used it for several years, …</td></tr><tr><td>&quot;A lot of work was put into this. I love the idea …</td></tr><tr><td>&quot;Very nice app I downloaded many app but it is the…</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 1)\n",
       "┌─────────────────────────────────────────────────────┐\n",
       "│ content                                             │\n",
       "│ ---                                                 │\n",
       "│ str                                                 │\n",
       "╞═════════════════════════════════════════════════════╡\n",
       "│ I love it :D I met great and fun people and this i… │\n",
       "│ I love Habitica! I've used it for several years, b… │\n",
       "│ A lot of work was put into this. I love the idea o… │\n",
       "│ Very nice app I downloaded many app but it is the … │\n",
       "└─────────────────────────────────────────────────────┘"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    df\n",
    "    .filter(pl.col('content').str.count_matches(r'very happy|best app|I love') > 2)\n",
    "    .select('content')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 1)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>userName</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;Sudhakar .S&quot;</td></tr><tr><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td></tr><tr><td>&quot;Louann Stoker&quot;</td></tr><tr><td>&quot;Jon Clemens&quot;</td></tr><tr><td>&quot;I Dewa Gede Nopi Ariana&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 1)\n",
       "┌──────────────────────────────────┐\n",
       "│ userName                         │\n",
       "│ ---                              │\n",
       "│ str                              │\n",
       "╞══════════════════════════════════╡\n",
       "│ Sudhakar .S                      │\n",
       "│ SKGflorida@bellsouth.net DAVID S │\n",
       "│ Louann Stoker                    │\n",
       "│ Jon Clemens                      │\n",
       "│ I Dewa Gede Nopi Ariana          │\n",
       "└──────────────────────────────────┘"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "( \n",
    "    df \n",
    "    .filter(pl.col('userName').str.len_chars() > 10) \n",
    "    .select('userName') \n",
    "    .head() \n",
    ") "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Converting strings into date, time, and datetime "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>reviewId</th><th>userName</th><th>userImage</th><th>content</th><th>score</th><th>thumbsUpCount</th><th>reviewCreatedVersion</th><th>at</th><th>replyContent</th><th>repliedAt</th><th>sortOrder</th><th>appId</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;gp:AOqpTOEhZuqSqqWnaKRgv-9ABYdajFUB0WugPGh-SG-fgH…</td><td>&quot;Eric Tie&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14GiG…</td><td>&quot;I cannot open the app anymore&quot;</td><td>1</td><td>0</td><td>&quot;5.4.0.6&quot;</td><td>&quot;2020-10-27 21:24:41&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOH0WP4IQKBZ2LrdNmFy_YmpPCVrV3diEU9KGm3fAX…</td><td>&quot;john alpha&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14Gjp…</td><td>&quot;I have been begging for a refund from this app fo…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 14:03:28&quot;</td><td>&quot;Please note that from checking our records, your …</td><td>&quot;2020-10-27 15:05:52&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOEMCkJB8Iq1p-r9dPwnSYadA5BkPWTf32Z1azuuTv…</td><td>&quot;Sudhakar .S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14Gid…</td><td>&quot;Very costly for the premium version (approx India…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 08:18:40&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOGFrUWuKGycpje8kszj3uwHN6tU_fd4gLVFy9z7hf…</td><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-75aK0WFnia…</td><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-26 13:28:07&quot;</td><td>&quot;What do you find troublesome about the update? We…</td><td>&quot;2020-10-26 14:58:29&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOHls7DW8wmDFzTkHwxuqFkdNQtKHmO6Pt9jhZEQ0Q…</td><td>&quot;Louann Stoker&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-pBcY_Z-qfB…</td><td>&quot;Dan Birthday Oct 28&quot;</td><td>1</td><td>0</td><td>&quot;5.6.0.7&quot;</td><td>&quot;2020-10-26 06:10:50&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌───────────┬───────────┬───────────┬───────────┬───┬───────────┬───────────┬───────────┬──────────┐\n",
       "│ reviewId  ┆ userName  ┆ userImage ┆ content   ┆ … ┆ replyCont ┆ repliedAt ┆ sortOrder ┆ appId    │\n",
       "│ ---       ┆ ---       ┆ ---       ┆ ---       ┆   ┆ ent       ┆ ---       ┆ ---       ┆ ---      │\n",
       "│ str       ┆ str       ┆ str       ┆ str       ┆   ┆ ---       ┆ str       ┆ str       ┆ str      │\n",
       "│           ┆           ┆           ┆           ┆   ┆ str       ┆           ┆           ┆          │\n",
       "╞═══════════╪═══════════╪═══════════╪═══════════╪═══╪═══════════╪═══════════╪═══════════╪══════════╡\n",
       "│ gp:AOqpTO ┆ Eric Tie  ┆ https://p ┆ I cannot  ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EhZuqSqqW ┆           ┆ lay-lh.go ┆ open the  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ naKRgv-9A ┆           ┆ ogleuserc ┆ app       ┆   ┆           ┆           ┆           ┆          │\n",
       "│ BYdajFUB0 ┆           ┆ ontent.co ┆ anymore   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WugPGh-SG ┆           ┆ m/a-/AOh1 ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ -fgH3…    ┆           ┆ 4GiGE…    ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ john      ┆ https://p ┆ I have    ┆ … ┆ Please    ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ H0WP4IQKB ┆ alpha     ┆ lay-lh.go ┆ been      ┆   ┆ note that ┆ 7         ┆           ┆ o        │\n",
       "│ Z2LrdNmFy ┆           ┆ ogleuserc ┆ begging   ┆   ┆ from      ┆ 15:05:52  ┆           ┆          │\n",
       "│ _YmpPCVrV ┆           ┆ ontent.co ┆ for a     ┆   ┆ checking  ┆           ┆           ┆          │\n",
       "│ 3diEU9KGm ┆           ┆ m/a-/AOh1 ┆ refund    ┆   ┆ our       ┆           ┆           ┆          │\n",
       "│ 3fAX6…    ┆           ┆ 4Gjpf…    ┆ from this ┆   ┆ records,  ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ app for…  ┆   ┆ your e…   ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Sudhakar  ┆ https://p ┆ Very      ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EMCkJB8Iq ┆ .S        ┆ lay-lh.go ┆ costly    ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ 1p-r9dPwn ┆           ┆ ogleuserc ┆ for the   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ SYadA5BkP ┆           ┆ ontent.co ┆ premium   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WTf32Z1az ┆           ┆ m/a-/AOh1 ┆ version   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ uuTvq…    ┆           ┆ 4GidH…    ┆ (approx   ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ Indian…   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ SKGflorid ┆ https://p ┆ Used to   ┆ … ┆ What do   ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ GFrUWuKGy ┆ a@bellsou ┆ lay-lh.go ┆ keep me   ┆   ┆ you find  ┆ 6         ┆           ┆ o        │\n",
       "│ cpje8kszj ┆ th.net    ┆ ogleuserc ┆ organized ┆   ┆ troubleso ┆ 14:58:29  ┆           ┆          │\n",
       "│ 3uwHN6tU_ ┆ DAVID S   ┆ ontent.co ┆ , but all ┆   ┆ me about  ┆           ┆           ┆          │\n",
       "│ fd4gLVFy9 ┆           ┆ m/-75aK0W ┆ the 2020  ┆   ┆ the       ┆           ┆           ┆          │\n",
       "│ z7hfG…    ┆           ┆ Fniac…    ┆ UPDATE…   ┆   ┆ update?   ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆           ┆   ┆ We'…      ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Louann    ┆ https://p ┆ Dan       ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ Hls7DW8wm ┆ Stoker    ┆ lay-lh.go ┆ Birthday  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ DFzTkHwxu ┆           ┆ ogleuserc ┆ Oct 28    ┆   ┆           ┆           ┆           ┆          │\n",
       "│ qFkdNQtKH ┆           ┆ ontent.co ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ mO6Pt9jhZ ┆           ┆ m/-pBcY_Z ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ EQ0Q2…    ┆           ┆ -qfB4…    ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.read_csv('../data/google_store_reviews.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>at</th><th>at(date)</th></tr><tr><td>str</td><td>date</td></tr></thead><tbody><tr><td>&quot;2020-10-27 21:24:41&quot;</td><td>2020-10-27</td></tr><tr><td>&quot;2020-10-27 14:03:28&quot;</td><td>2020-10-27</td></tr><tr><td>&quot;2020-10-27 08:18:40&quot;</td><td>2020-10-27</td></tr><tr><td>&quot;2020-10-26 13:28:07&quot;</td><td>2020-10-26</td></tr><tr><td>&quot;2020-10-26 06:10:50&quot;</td><td>2020-10-26</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌─────────────────────┬────────────┐\n",
       "│ at                  ┆ at(date)   │\n",
       "│ ---                 ┆ ---        │\n",
       "│ str                 ┆ date       │\n",
       "╞═════════════════════╪════════════╡\n",
       "│ 2020-10-27 21:24:41 ┆ 2020-10-27 │\n",
       "│ 2020-10-27 14:03:28 ┆ 2020-10-27 │\n",
       "│ 2020-10-27 08:18:40 ┆ 2020-10-27 │\n",
       "│ 2020-10-26 13:28:07 ┆ 2020-10-26 │\n",
       "│ 2020-10-26 06:10:50 ┆ 2020-10-26 │\n",
       "└─────────────────────┴────────────┘"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'at',\n",
    "    pl.col('at').str.to_date(format='%Y-%m-%d %H:%M:%S').alias('at(date)')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>at</th><th>at(time)</th></tr><tr><td>str</td><td>time</td></tr></thead><tbody><tr><td>&quot;2020-10-27 21:24:41&quot;</td><td>21:24:41</td></tr><tr><td>&quot;2020-10-27 14:03:28&quot;</td><td>14:03:28</td></tr><tr><td>&quot;2020-10-27 08:18:40&quot;</td><td>08:18:40</td></tr><tr><td>&quot;2020-10-26 13:28:07&quot;</td><td>13:28:07</td></tr><tr><td>&quot;2020-10-26 06:10:50&quot;</td><td>06:10:50</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌─────────────────────┬──────────┐\n",
       "│ at                  ┆ at(time) │\n",
       "│ ---                 ┆ ---      │\n",
       "│ str                 ┆ time     │\n",
       "╞═════════════════════╪══════════╡\n",
       "│ 2020-10-27 21:24:41 ┆ 21:24:41 │\n",
       "│ 2020-10-27 14:03:28 ┆ 14:03:28 │\n",
       "│ 2020-10-27 08:18:40 ┆ 08:18:40 │\n",
       "│ 2020-10-26 13:28:07 ┆ 13:28:07 │\n",
       "│ 2020-10-26 06:10:50 ┆ 06:10:50 │\n",
       "└─────────────────────┴──────────┘"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'at',\n",
    "    pl.col('at').str.to_time(format='%Y-%m-%d %H:%M:%S').alias('at(time)')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>at</th><th>at(datetime)</th></tr><tr><td>str</td><td>datetime[μs]</td></tr></thead><tbody><tr><td>&quot;2020-10-27 21:24:41&quot;</td><td>2020-10-27 21:24:41</td></tr><tr><td>&quot;2020-10-27 14:03:28&quot;</td><td>2020-10-27 14:03:28</td></tr><tr><td>&quot;2020-10-27 08:18:40&quot;</td><td>2020-10-27 08:18:40</td></tr><tr><td>&quot;2020-10-26 13:28:07&quot;</td><td>2020-10-26 13:28:07</td></tr><tr><td>&quot;2020-10-26 06:10:50&quot;</td><td>2020-10-26 06:10:50</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌─────────────────────┬─────────────────────┐\n",
       "│ at                  ┆ at(datetime)        │\n",
       "│ ---                 ┆ ---                 │\n",
       "│ str                 ┆ datetime[μs]        │\n",
       "╞═════════════════════╪═════════════════════╡\n",
       "│ 2020-10-27 21:24:41 ┆ 2020-10-27 21:24:41 │\n",
       "│ 2020-10-27 14:03:28 ┆ 2020-10-27 14:03:28 │\n",
       "│ 2020-10-27 08:18:40 ┆ 2020-10-27 08:18:40 │\n",
       "│ 2020-10-26 13:28:07 ┆ 2020-10-26 13:28:07 │\n",
       "│ 2020-10-26 06:10:50 ┆ 2020-10-26 06:10:50 │\n",
       "└─────────────────────┴─────────────────────┘"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'at',\n",
    "    pl.col('at').str.to_datetime(format='%Y-%m-%d %H:%M:%S').alias('at(datetime)')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 4)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>at</th><th>at(date)</th><th>at(time)</th><th>at(datetime)</th></tr><tr><td>str</td><td>date</td><td>time</td><td>datetime[μs]</td></tr></thead><tbody><tr><td>&quot;2020-10-27 21:24:41&quot;</td><td>2020-10-27</td><td>21:24:41</td><td>2020-10-27 21:24:41</td></tr><tr><td>&quot;2020-10-27 14:03:28&quot;</td><td>2020-10-27</td><td>14:03:28</td><td>2020-10-27 14:03:28</td></tr><tr><td>&quot;2020-10-27 08:18:40&quot;</td><td>2020-10-27</td><td>08:18:40</td><td>2020-10-27 08:18:40</td></tr><tr><td>&quot;2020-10-26 13:28:07&quot;</td><td>2020-10-26</td><td>13:28:07</td><td>2020-10-26 13:28:07</td></tr><tr><td>&quot;2020-10-26 06:10:50&quot;</td><td>2020-10-26</td><td>06:10:50</td><td>2020-10-26 06:10:50</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 4)\n",
       "┌─────────────────────┬────────────┬──────────┬─────────────────────┐\n",
       "│ at                  ┆ at(date)   ┆ at(time) ┆ at(datetime)        │\n",
       "│ ---                 ┆ ---        ┆ ---      ┆ ---                 │\n",
       "│ str                 ┆ date       ┆ time     ┆ datetime[μs]        │\n",
       "╞═════════════════════╪════════════╪══════════╪═════════════════════╡\n",
       "│ 2020-10-27 21:24:41 ┆ 2020-10-27 ┆ 21:24:41 ┆ 2020-10-27 21:24:41 │\n",
       "│ 2020-10-27 14:03:28 ┆ 2020-10-27 ┆ 14:03:28 ┆ 2020-10-27 14:03:28 │\n",
       "│ 2020-10-27 08:18:40 ┆ 2020-10-27 ┆ 08:18:40 ┆ 2020-10-27 08:18:40 │\n",
       "│ 2020-10-26 13:28:07 ┆ 2020-10-26 ┆ 13:28:07 ┆ 2020-10-26 13:28:07 │\n",
       "│ 2020-10-26 06:10:50 ┆ 2020-10-26 ┆ 06:10:50 ┆ 2020-10-26 06:10:50 │\n",
       "└─────────────────────┴────────────┴──────────┴─────────────────────┘"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'at',\n",
    "    pl.col('at').str.strptime(pl.Date, '%Y-%m-%d %H:%M:%S').alias('at(date)'),\n",
    "    pl.col('at').str.strptime(pl.Time, '%Y-%m-%d %H:%M:%S').alias('at(time)'),\n",
    "    pl.col('at').str.strptime(pl.Datetime, '%Y-%m-%d %H:%M:%S').alias('at(datetime)')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Extracting substrings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>reviewId</th><th>userName</th><th>userImage</th><th>content</th><th>score</th><th>thumbsUpCount</th><th>reviewCreatedVersion</th><th>at</th><th>replyContent</th><th>repliedAt</th><th>sortOrder</th><th>appId</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;gp:AOqpTOEhZuqSqqWnaKRgv-9ABYdajFUB0WugPGh-SG-fgH…</td><td>&quot;Eric Tie&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14GiG…</td><td>&quot;I cannot open the app anymore&quot;</td><td>1</td><td>0</td><td>&quot;5.4.0.6&quot;</td><td>&quot;2020-10-27 21:24:41&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOH0WP4IQKBZ2LrdNmFy_YmpPCVrV3diEU9KGm3fAX…</td><td>&quot;john alpha&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14Gjp…</td><td>&quot;I have been begging for a refund from this app fo…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 14:03:28&quot;</td><td>&quot;Please note that from checking our records, your …</td><td>&quot;2020-10-27 15:05:52&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOEMCkJB8Iq1p-r9dPwnSYadA5BkPWTf32Z1azuuTv…</td><td>&quot;Sudhakar .S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14Gid…</td><td>&quot;Very costly for the premium version (approx India…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 08:18:40&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOGFrUWuKGycpje8kszj3uwHN6tU_fd4gLVFy9z7hf…</td><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-75aK0WFnia…</td><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-26 13:28:07&quot;</td><td>&quot;What do you find troublesome about the update? We…</td><td>&quot;2020-10-26 14:58:29&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOHls7DW8wmDFzTkHwxuqFkdNQtKHmO6Pt9jhZEQ0Q…</td><td>&quot;Louann Stoker&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-pBcY_Z-qfB…</td><td>&quot;Dan Birthday Oct 28&quot;</td><td>1</td><td>0</td><td>&quot;5.6.0.7&quot;</td><td>&quot;2020-10-26 06:10:50&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌───────────┬───────────┬───────────┬───────────┬───┬───────────┬───────────┬───────────┬──────────┐\n",
       "│ reviewId  ┆ userName  ┆ userImage ┆ content   ┆ … ┆ replyCont ┆ repliedAt ┆ sortOrder ┆ appId    │\n",
       "│ ---       ┆ ---       ┆ ---       ┆ ---       ┆   ┆ ent       ┆ ---       ┆ ---       ┆ ---      │\n",
       "│ str       ┆ str       ┆ str       ┆ str       ┆   ┆ ---       ┆ str       ┆ str       ┆ str      │\n",
       "│           ┆           ┆           ┆           ┆   ┆ str       ┆           ┆           ┆          │\n",
       "╞═══════════╪═══════════╪═══════════╪═══════════╪═══╪═══════════╪═══════════╪═══════════╪══════════╡\n",
       "│ gp:AOqpTO ┆ Eric Tie  ┆ https://p ┆ I cannot  ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EhZuqSqqW ┆           ┆ lay-lh.go ┆ open the  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ naKRgv-9A ┆           ┆ ogleuserc ┆ app       ┆   ┆           ┆           ┆           ┆          │\n",
       "│ BYdajFUB0 ┆           ┆ ontent.co ┆ anymore   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WugPGh-SG ┆           ┆ m/a-/AOh1 ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ -fgH3…    ┆           ┆ 4GiGE…    ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ john      ┆ https://p ┆ I have    ┆ … ┆ Please    ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ H0WP4IQKB ┆ alpha     ┆ lay-lh.go ┆ been      ┆   ┆ note that ┆ 7         ┆           ┆ o        │\n",
       "│ Z2LrdNmFy ┆           ┆ ogleuserc ┆ begging   ┆   ┆ from      ┆ 15:05:52  ┆           ┆          │\n",
       "│ _YmpPCVrV ┆           ┆ ontent.co ┆ for a     ┆   ┆ checking  ┆           ┆           ┆          │\n",
       "│ 3diEU9KGm ┆           ┆ m/a-/AOh1 ┆ refund    ┆   ┆ our       ┆           ┆           ┆          │\n",
       "│ 3fAX6…    ┆           ┆ 4Gjpf…    ┆ from this ┆   ┆ records,  ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ app for…  ┆   ┆ your e…   ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Sudhakar  ┆ https://p ┆ Very      ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EMCkJB8Iq ┆ .S        ┆ lay-lh.go ┆ costly    ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ 1p-r9dPwn ┆           ┆ ogleuserc ┆ for the   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ SYadA5BkP ┆           ┆ ontent.co ┆ premium   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WTf32Z1az ┆           ┆ m/a-/AOh1 ┆ version   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ uuTvq…    ┆           ┆ 4GidH…    ┆ (approx   ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ Indian…   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ SKGflorid ┆ https://p ┆ Used to   ┆ … ┆ What do   ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ GFrUWuKGy ┆ a@bellsou ┆ lay-lh.go ┆ keep me   ┆   ┆ you find  ┆ 6         ┆           ┆ o        │\n",
       "│ cpje8kszj ┆ th.net    ┆ ogleuserc ┆ organized ┆   ┆ troubleso ┆ 14:58:29  ┆           ┆          │\n",
       "│ 3uwHN6tU_ ┆ DAVID S   ┆ ontent.co ┆ , but all ┆   ┆ me about  ┆           ┆           ┆          │\n",
       "│ fd4gLVFy9 ┆           ┆ m/-75aK0W ┆ the 2020  ┆   ┆ the       ┆           ┆           ┆          │\n",
       "│ z7hfG…    ┆           ┆ Fniac…    ┆ UPDATE…   ┆   ┆ update?   ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆           ┆   ┆ We'…      ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Louann    ┆ https://p ┆ Dan       ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ Hls7DW8wm ┆ Stoker    ┆ lay-lh.go ┆ Birthday  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ DFzTkHwxu ┆           ┆ ogleuserc ┆ Oct 28    ┆   ┆           ┆           ┆           ┆          │\n",
       "│ qFkdNQtKH ┆           ┆ ontent.co ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ mO6Pt9jhZ ┆           ┆ m/-pBcY_Z ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ EQ0Q2…    ┆           ┆ -qfB4…    ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.read_csv('../data/google_store_reviews.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>userName</th><th>4thCharAndAfter</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;Eric Tie&quot;</td><td>&quot;c Tie&quot;</td></tr><tr><td>&quot;john alpha&quot;</td><td>&quot;n alpha&quot;</td></tr><tr><td>&quot;Sudhakar .S&quot;</td><td>&quot;hakar .S&quot;</td></tr><tr><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td><td>&quot;florida@bellsouth.net DAVID S&quot;</td></tr><tr><td>&quot;Louann Stoker&quot;</td><td>&quot;ann Stoker&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌──────────────────────────────────┬───────────────────────────────┐\n",
       "│ userName                         ┆ 4thCharAndAfter               │\n",
       "│ ---                              ┆ ---                           │\n",
       "│ str                              ┆ str                           │\n",
       "╞══════════════════════════════════╪═══════════════════════════════╡\n",
       "│ Eric Tie                         ┆ c Tie                         │\n",
       "│ john alpha                       ┆ n alpha                       │\n",
       "│ Sudhakar .S                      ┆ hakar .S                      │\n",
       "│ SKGflorida@bellsouth.net DAVID S ┆ florida@bellsouth.net DAVID S │\n",
       "│ Louann Stoker                    ┆ ann Stoker                    │\n",
       "└──────────────────────────────────┴───────────────────────────────┘"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'userName',\n",
    "    pl.col('userName').str.slice(3).alias('4thCharAndAfter')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>userName</th><th>5CharsAfter4thChar</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;Eric Tie&quot;</td><td>&quot;c Tie&quot;</td></tr><tr><td>&quot;john alpha&quot;</td><td>&quot;n alp&quot;</td></tr><tr><td>&quot;Sudhakar .S&quot;</td><td>&quot;hakar&quot;</td></tr><tr><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td><td>&quot;flori&quot;</td></tr><tr><td>&quot;Louann Stoker&quot;</td><td>&quot;ann S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌──────────────────────────────────┬────────────────────┐\n",
       "│ userName                         ┆ 5CharsAfter4thChar │\n",
       "│ ---                              ┆ ---                │\n",
       "│ str                              ┆ str                │\n",
       "╞══════════════════════════════════╪════════════════════╡\n",
       "│ Eric Tie                         ┆ c Tie              │\n",
       "│ john alpha                       ┆ n alp              │\n",
       "│ Sudhakar .S                      ┆ hakar              │\n",
       "│ SKGflorida@bellsouth.net DAVID S ┆ flori              │\n",
       "│ Louann Stoker                    ┆ ann S              │\n",
       "└──────────────────────────────────┴────────────────────┘"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'userName',\n",
    "    pl.col('userName').str.slice(3, 5).alias('5CharsAfter4thChar')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>userName</th><th>TheLastToSecondChar</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;Eric Tie&quot;</td><td>&quot;i&quot;</td></tr><tr><td>&quot;john alpha&quot;</td><td>&quot;h&quot;</td></tr><tr><td>&quot;Sudhakar .S&quot;</td><td>&quot;.&quot;</td></tr><tr><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td><td>&quot; &quot;</td></tr><tr><td>&quot;Louann Stoker&quot;</td><td>&quot;e&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌──────────────────────────────────┬─────────────────────┐\n",
       "│ userName                         ┆ TheLastToSecondChar │\n",
       "│ ---                              ┆ ---                 │\n",
       "│ str                              ┆ str                 │\n",
       "╞══════════════════════════════════╪═════════════════════╡\n",
       "│ Eric Tie                         ┆ i                   │\n",
       "│ john alpha                       ┆ h                   │\n",
       "│ Sudhakar .S                      ┆ .                   │\n",
       "│ SKGflorida@bellsouth.net DAVID S ┆                     │\n",
       "│ Louann Stoker                    ┆ e                   │\n",
       "└──────────────────────────────────┴─────────────────────┘"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'userName',\n",
    "    pl.col('userName').str.slice(-2, 1).alias('TheLastToSecondChar')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>extract</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>&quot;I&quot;</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>&quot;I&quot;</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>&quot;Very&quot;</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>&quot;Used&quot;</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>&quot;Dan&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌─────────────────────────────────────────────────────┬─────────┐\n",
       "│ content                                             ┆ extract │\n",
       "│ ---                                                 ┆ ---     │\n",
       "│ str                                                 ┆ str     │\n",
       "╞═════════════════════════════════════════════════════╪═════════╡\n",
       "│ I cannot open the app anymore                       ┆ I       │\n",
       "│ I have been begging for a refund from this app for… ┆ I       │\n",
       "│ Very costly for the premium version (approx Indian… ┆ Very    │\n",
       "│ Used to keep me organized, but all the 2020 UPDATE… ┆ Used    │\n",
       "│ Dan Birthday Oct 28                                 ┆ Dan     │\n",
       "└─────────────────────────────────────────────────────┴─────────┘"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content')\n",
    "    .str.extract(r'([A-Za-z]+)')\n",
    "    .alias('extract')\n",
    ").head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 4)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>extract whole matches specified</th><th>extract group 1 specified</th><th>extract group 2 specified</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>null</td><td>null</td><td>null</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>null</td><td>null</td><td>null</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>&quot;ees 910&quot;</td><td>&quot;ees&quot;</td><td>&quot;910&quot;</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>&quot;the 2020&quot;</td><td>&quot;the&quot;</td><td>&quot;2020&quot;</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>&quot;Oct 28&quot;</td><td>&quot;Oct&quot;</td><td>&quot;28&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 4)\n",
       "┌──────────────────────────────────────┬───────────────────────┬─────────────────┬─────────────────┐\n",
       "│ content                              ┆ extract whole matches ┆ extract group 1 ┆ extract group 2 │\n",
       "│ ---                                  ┆ specified             ┆ specified       ┆ specified       │\n",
       "│ str                                  ┆ ---                   ┆ ---             ┆ ---             │\n",
       "│                                      ┆ str                   ┆ str             ┆ str             │\n",
       "╞══════════════════════════════════════╪═══════════════════════╪═════════════════╪═════════════════╡\n",
       "│ I cannot open the app anymore        ┆ null                  ┆ null            ┆ null            │\n",
       "│ I have been begging for a refund     ┆ null                  ┆ null            ┆ null            │\n",
       "│ from this app for…                   ┆                       ┆                 ┆                 │\n",
       "│ Very costly for the premium version  ┆ ees 910               ┆ ees             ┆ 910             │\n",
       "│ (approx Indian…                      ┆                       ┆                 ┆                 │\n",
       "│ Used to keep me organized, but all   ┆ the 2020              ┆ the             ┆ 2020            │\n",
       "│ the 2020 UPDATE…                     ┆                       ┆                 ┆                 │\n",
       "│ Dan Birthday Oct 28                  ┆ Oct 28                ┆ Oct             ┆ 28              │\n",
       "└──────────────────────────────────────┴───────────────────────┴─────────────────┴─────────────────┘"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content')\n",
    "    .str.extract(r'([A-Za-z]{3}) ([0-9]+)', 0)\n",
    "    .alias('extract whole matches specified'),\n",
    "    pl.col('content')\n",
    "    .str.extract(r'([A-Za-z]{3}) ([0-9]+)', 1)\n",
    "    .alias('extract group 1 specified'),\n",
    "    pl.col('content')\n",
    "    .str.extract(r'([A-Za-z]{3}) ([0-9]+)', 2)\n",
    "    .alias('extract group 2 specified')\n",
    ").head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>extract</th><th>extract_all</th></tr><tr><td>str</td><td>str</td><td>list[str]</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>&quot;I&quot;</td><td>[&quot;I&quot;, &quot;cannot&quot;, … &quot;anymore&quot;]</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>&quot;I&quot;</td><td>[&quot;I&quot;, &quot;have&quot;, … &quot;me&quot;]</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>&quot;Very&quot;</td><td>[&quot;Very&quot;, &quot;costly&quot;, … &quot;better&quot;]</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>&quot;Used&quot;</td><td>[&quot;Used&quot;, &quot;to&quot;, … &quot;salary&quot;]</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>&quot;Dan&quot;</td><td>[&quot;Dan&quot;, &quot;Birthday&quot;, &quot;Oct&quot;]</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 3)\n",
       "┌─────────────────────────────────────────────────────┬─────────┬────────────────────────────────┐\n",
       "│ content                                             ┆ extract ┆ extract_all                    │\n",
       "│ ---                                                 ┆ ---     ┆ ---                            │\n",
       "│ str                                                 ┆ str     ┆ list[str]                      │\n",
       "╞═════════════════════════════════════════════════════╪═════════╪════════════════════════════════╡\n",
       "│ I cannot open the app anymore                       ┆ I       ┆ [\"I\", \"cannot\", … \"anymore\"]   │\n",
       "│ I have been begging for a refund from this app for… ┆ I       ┆ [\"I\", \"have\", … \"me\"]          │\n",
       "│ Very costly for the premium version (approx Indian… ┆ Very    ┆ [\"Very\", \"costly\", … \"better\"] │\n",
       "│ Used to keep me organized, but all the 2020 UPDATE… ┆ Used    ┆ [\"Used\", \"to\", … \"salary\"]     │\n",
       "│ Dan Birthday Oct 28                                 ┆ Dan     ┆ [\"Dan\", \"Birthday\", \"Oct\"]     │\n",
       "└─────────────────────────────────────────────────────┴─────────┴────────────────────────────────┘"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content')\n",
    "    .str.extract(r'([A-Za-z]+)')\n",
    "    .alias('extract'),\n",
    "    pl.col('content')\n",
    "    .str.extract_all(r'([A-Za-z]+)')\n",
    "    .alias('extract_all')\n",
    ").head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>extract</th><th>extract_all</th></tr><tr><td>str</td><td>str</td><td>list[str]</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>&quot;I&quot;</td><td>[&quot;I&quot;, &quot;cannot&quot;, … &quot;anymore&quot;]</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>&quot;I&quot;</td><td>[&quot;I&quot;, &quot;have&quot;, … &quot;me&quot;]</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>&quot;Very&quot;</td><td>[&quot;Very&quot;, &quot;costly&quot;, … &quot;better&quot;]</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>&quot;Used&quot;</td><td>[&quot;Used&quot;, &quot;to&quot;, … &quot;salary&quot;]</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>&quot;Dan&quot;</td><td>[&quot;Dan&quot;, &quot;Birthday&quot;, &quot;Oct&quot;]</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 3)\n",
       "┌─────────────────────────────────────────────────────┬─────────┬────────────────────────────────┐\n",
       "│ content                                             ┆ extract ┆ extract_all                    │\n",
       "│ ---                                                 ┆ ---     ┆ ---                            │\n",
       "│ str                                                 ┆ str     ┆ list[str]                      │\n",
       "╞═════════════════════════════════════════════════════╪═════════╪════════════════════════════════╡\n",
       "│ I cannot open the app anymore                       ┆ I       ┆ [\"I\", \"cannot\", … \"anymore\"]   │\n",
       "│ I have been begging for a refund from this app for… ┆ I       ┆ [\"I\", \"have\", … \"me\"]          │\n",
       "│ Very costly for the premium version (approx Indian… ┆ Very    ┆ [\"Very\", \"costly\", … \"better\"] │\n",
       "│ Used to keep me organized, but all the 2020 UPDATE… ┆ Used    ┆ [\"Used\", \"to\", … \"salary\"]     │\n",
       "│ Dan Birthday Oct 28                                 ┆ Dan     ┆ [\"Dan\", \"Birthday\", \"Oct\"]     │\n",
       "└─────────────────────────────────────────────────────┴─────────┴────────────────────────────────┘"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content')\n",
    "    .str.extract(r'([A-Za-z]+)')\n",
    "    .alias('extract'),\n",
    "    pl.col('content')\n",
    "    .str.extract_all(r'([A-Za-z]+)')\n",
    "    .alias('extract_all')\n",
    ").head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>extract</th><th>extract_groups</th></tr><tr><td>str</td><td>str</td><td>struct[2]</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>null</td><td>{null,null}</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>null</td><td>{null,null}</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>&quot;ees 910&quot;</td><td>{&quot;ees&quot;,&quot;910&quot;}</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>&quot;the 2020&quot;</td><td>{&quot;the&quot;,&quot;2020&quot;}</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>&quot;Oct 28&quot;</td><td>{&quot;Oct&quot;,&quot;28&quot;}</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 3)\n",
       "┌─────────────────────────────────────────────────────┬──────────┬────────────────┐\n",
       "│ content                                             ┆ extract  ┆ extract_groups │\n",
       "│ ---                                                 ┆ ---      ┆ ---            │\n",
       "│ str                                                 ┆ str      ┆ struct[2]      │\n",
       "╞═════════════════════════════════════════════════════╪══════════╪════════════════╡\n",
       "│ I cannot open the app anymore                       ┆ null     ┆ {null,null}    │\n",
       "│ I have been begging for a refund from this app for… ┆ null     ┆ {null,null}    │\n",
       "│ Very costly for the premium version (approx Indian… ┆ ees 910  ┆ {\"ees\",\"910\"}  │\n",
       "│ Used to keep me organized, but all the 2020 UPDATE… ┆ the 2020 ┆ {\"the\",\"2020\"} │\n",
       "│ Dan Birthday Oct 28                                 ┆ Oct 28   ┆ {\"Oct\",\"28\"}   │\n",
       "└─────────────────────────────────────────────────────┴──────────┴────────────────┘"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content')\n",
    "    .str.extract(r'([A-Za-z]{3}) ([0-9]+)', 0)\n",
    "    .alias('extract'),\n",
    "    pl.col('content')\n",
    "    .str.extract_groups(r'([A-Za-z]{3}) ([0-9]+)')\n",
    "    .alias('extract_groups')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There is more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>extract_all</th></tr><tr><td>str</td><td>list[str]</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>[&quot;I&quot;, &quot;cannot&quot;, … &quot;anymore&quot;]</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>[&quot;I&quot;, &quot;have&quot;, … &quot;me&quot;]</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>[&quot;Very&quot;, &quot;costly&quot;, … &quot;better&quot;]</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>[&quot;Used&quot;, &quot;to&quot;, … &quot;salary&quot;]</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>[&quot;Dan&quot;, &quot;Birthday&quot;, &quot;Oct&quot;]</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌─────────────────────────────────────────────────────┬────────────────────────────────┐\n",
       "│ content                                             ┆ extract_all                    │\n",
       "│ ---                                                 ┆ ---                            │\n",
       "│ str                                                 ┆ list[str]                      │\n",
       "╞═════════════════════════════════════════════════════╪════════════════════════════════╡\n",
       "│ I cannot open the app anymore                       ┆ [\"I\", \"cannot\", … \"anymore\"]   │\n",
       "│ I have been begging for a refund from this app for… ┆ [\"I\", \"have\", … \"me\"]          │\n",
       "│ Very costly for the premium version (approx Indian… ┆ [\"Very\", \"costly\", … \"better\"] │\n",
       "│ Used to keep me organized, but all the 2020 UPDATE… ┆ [\"Used\", \"to\", … \"salary\"]     │\n",
       "│ Dan Birthday Oct 28                                 ┆ [\"Dan\", \"Birthday\", \"Oct\"]     │\n",
       "└─────────────────────────────────────────────────────┴────────────────────────────────┘"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content')\n",
    "    .str.extract_all(r'(?i)([A-Z]+)')\n",
    "    .alias('extract_all')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cleaning strings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 1)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 1)\n",
       "┌─────────────────────┐\n",
       "│ text                │\n",
       "│ ---                 │\n",
       "│ str                 │\n",
       "╞═════════════════════╡\n",
       "│   I aM a HUmAn.     │\n",
       "│ it is NOT   easy!   │\n",
       "│  WHY are You cool   │\n",
       "└─────────────────────┘"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.DataFrame(\n",
    "    {\n",
    "        'text': [\n",
    "            '  I aM a HUmAn.  ', \n",
    "            'it is NOT   easy!  ', \n",
    "            ' WHY are You cool'\n",
    "        ]\n",
    "    }\n",
    ")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>stripped_text</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;I aM a HUmAn.&quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;it is NOT   easy!&quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot;WHY are You cool&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌─────────────────────┬───────────────────┐\n",
       "│ text                ┆ stripped_text     │\n",
       "│ ---                 ┆ ---               │\n",
       "│ str                 ┆ str               │\n",
       "╞═════════════════════╪═══════════════════╡\n",
       "│   I aM a HUmAn.     ┆ I aM a HUmAn.     │\n",
       "│ it is NOT   easy!   ┆ it is NOT   easy! │\n",
       "│  WHY are You cool   ┆ WHY are You cool  │\n",
       "└─────────────────────┴───────────────────┘"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.strip_chars()\n",
    "    .alias('stripped_text')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>replaced_text</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;  I new_aM a HUmAn.  &quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;it is NOT   enew_asy!  &quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot; WHY new_are You cool&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌─────────────────────┬─────────────────────────┐\n",
       "│ text                ┆ replaced_text           │\n",
       "│ ---                 ┆ ---                     │\n",
       "│ str                 ┆ str                     │\n",
       "╞═════════════════════╪═════════════════════════╡\n",
       "│   I aM a HUmAn.     ┆   I new_aM a HUmAn.     │\n",
       "│ it is NOT   easy!   ┆ it is NOT   enew_asy!   │\n",
       "│  WHY are You cool   ┆  WHY new_are You cool   │\n",
       "└─────────────────────┴─────────────────────────┘"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.replace('a', 'new_a', literal=True, n=1)\n",
    "    .alias('replaced_text')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>replaced_all_text</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;  I new_aM new_a HUmAn.  &quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;it is NOT   enew_asy!  &quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot; WHY new_are You cool&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌─────────────────────┬───────────────────────────┐\n",
       "│ text                ┆ replaced_all_text         │\n",
       "│ ---                 ┆ ---                       │\n",
       "│ str                 ┆ str                       │\n",
       "╞═════════════════════╪═══════════════════════════╡\n",
       "│   I aM a HUmAn.     ┆   I new_aM new_a HUmAn.   │\n",
       "│ it is NOT   easy!   ┆ it is NOT   enew_asy!     │\n",
       "│  WHY are You cool   ┆  WHY new_are You cool     │\n",
       "└─────────────────────┴───────────────────────────┘"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.replace_all('a', 'new_a', literal=True)\n",
    "    .alias('replaced_all_text')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>title_case</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;  I Am A Human.  &quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;It Is Not   Easy!  &quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot; Why Are You Cool&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌─────────────────────┬─────────────────────┐\n",
       "│ text                ┆ title_case          │\n",
       "│ ---                 ┆ ---                 │\n",
       "│ str                 ┆ str                 │\n",
       "╞═════════════════════╪═════════════════════╡\n",
       "│   I aM a HUmAn.     ┆   I Am A Human.     │\n",
       "│ it is NOT   easy!   ┆ It Is Not   Easy!   │\n",
       "│  WHY are You cool   ┆  Why Are You Cool   │\n",
       "└─────────────────────┴─────────────────────┘"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.to_titlecase().alias('title_case')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>lower_case</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;  i am a human.  &quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;it is not   easy!  &quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot; why are you cool&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌─────────────────────┬─────────────────────┐\n",
       "│ text                ┆ lower_case          │\n",
       "│ ---                 ┆ ---                 │\n",
       "│ str                 ┆ str                 │\n",
       "╞═════════════════════╪═════════════════════╡\n",
       "│   I aM a HUmAn.     ┆   i am a human.     │\n",
       "│ it is NOT   easy!   ┆ it is not   easy!   │\n",
       "│  WHY are You cool   ┆  why are you cool   │\n",
       "└─────────────────────┴─────────────────────┘"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.to_lowercase().alias('lower_case')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>upper_case</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;  I AM A HUMAN.  &quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;IT IS NOT   EASY!  &quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot; WHY ARE YOU COOL&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌─────────────────────┬─────────────────────┐\n",
       "│ text                ┆ upper_case          │\n",
       "│ ---                 ┆ ---                 │\n",
       "│ str                 ┆ str                 │\n",
       "╞═════════════════════╪═════════════════════╡\n",
       "│   I aM a HUmAn.     ┆   I AM A HUMAN.     │\n",
       "│ it is NOT   easy!   ┆ IT IS NOT   EASY!   │\n",
       "│  WHY are You cool   ┆  WHY ARE YOU COOL   │\n",
       "└─────────────────────┴─────────────────────┘"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.to_uppercase().alias('upper_case')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>pad_start</th><th>pad_end</th></tr><tr><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;~~~  I aM a HUmAn.  &quot;</td><td>&quot;  I aM a HUmAn.  ~~~&quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;~it is NOT   easy!  &quot;</td><td>&quot;it is NOT   easy!  ~&quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot;~~~ WHY are You cool&quot;</td><td>&quot; WHY are You cool~~~&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 3)\n",
       "┌─────────────────────┬──────────────────────┬──────────────────────┐\n",
       "│ text                ┆ pad_start            ┆ pad_end              │\n",
       "│ ---                 ┆ ---                  ┆ ---                  │\n",
       "│ str                 ┆ str                  ┆ str                  │\n",
       "╞═════════════════════╪══════════════════════╪══════════════════════╡\n",
       "│   I aM a HUmAn.     ┆ ~~~  I aM a HUmAn.   ┆   I aM a HUmAn.  ~~~ │\n",
       "│ it is NOT   easy!   ┆ ~it is NOT   easy!   ┆ it is NOT   easy!  ~ │\n",
       "│  WHY are You cool   ┆ ~~~ WHY are You cool ┆  WHY are You cool~~~ │\n",
       "└─────────────────────┴──────────────────────┴──────────────────────┘"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.pad_start(20, '~').alias('pad_start'),\n",
    "    pl.col('text')\n",
    "    .str.pad_end(20, '~').alias('pad_end'),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>text</th><th>pad_start</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;  I aM a HUmAn.  &quot;</td><td>&quot;000  I aM a HUmAn.  &quot;</td></tr><tr><td>&quot;it is NOT   easy!  &quot;</td><td>&quot;0it is NOT   easy!  &quot;</td></tr><tr><td>&quot; WHY are You cool&quot;</td><td>&quot;000 WHY are You cool&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌─────────────────────┬──────────────────────┐\n",
       "│ text                ┆ pad_start            │\n",
       "│ ---                 ┆ ---                  │\n",
       "│ str                 ┆ str                  │\n",
       "╞═════════════════════╪══════════════════════╡\n",
       "│   I aM a HUmAn.     ┆ 000  I aM a HUmAn.   │\n",
       "│ it is NOT   easy!   ┆ 0it is NOT   easy!   │\n",
       "│  WHY are You cool   ┆ 000 WHY are You cool │\n",
       "└─────────────────────┴──────────────────────┘"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'text',\n",
    "    pl.col('text')\n",
    "    .str.pad_start(20, '0').alias('pad_start')\n",
    "  \n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Splitting strings into lists and structs "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>reviewId</th><th>userName</th><th>userImage</th><th>content</th><th>score</th><th>thumbsUpCount</th><th>reviewCreatedVersion</th><th>at</th><th>replyContent</th><th>repliedAt</th><th>sortOrder</th><th>appId</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;gp:AOqpTOEhZuqSqqWnaKRgv-9ABYdajFUB0WugPGh-SG-fgH…</td><td>&quot;Eric Tie&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14GiG…</td><td>&quot;I cannot open the app anymore&quot;</td><td>1</td><td>0</td><td>&quot;5.4.0.6&quot;</td><td>&quot;2020-10-27 21:24:41&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOH0WP4IQKBZ2LrdNmFy_YmpPCVrV3diEU9KGm3fAX…</td><td>&quot;john alpha&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14Gjp…</td><td>&quot;I have been begging for a refund from this app fo…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 14:03:28&quot;</td><td>&quot;Please note that from checking our records, your …</td><td>&quot;2020-10-27 15:05:52&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOEMCkJB8Iq1p-r9dPwnSYadA5BkPWTf32Z1azuuTv…</td><td>&quot;Sudhakar .S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/a-/AOh14Gid…</td><td>&quot;Very costly for the premium version (approx India…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-27 08:18:40&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOGFrUWuKGycpje8kszj3uwHN6tU_fd4gLVFy9z7hf…</td><td>&quot;SKGflorida@bellsouth.net DAVID S&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-75aK0WFnia…</td><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>1</td><td>0</td><td>null</td><td>&quot;2020-10-26 13:28:07&quot;</td><td>&quot;What do you find troublesome about the update? We…</td><td>&quot;2020-10-26 14:58:29&quot;</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr><tr><td>&quot;gp:AOqpTOHls7DW8wmDFzTkHwxuqFkdNQtKHmO6Pt9jhZEQ0Q…</td><td>&quot;Louann Stoker&quot;</td><td>&quot;https://play-lh.googleusercontent.com/-pBcY_Z-qfB…</td><td>&quot;Dan Birthday Oct 28&quot;</td><td>1</td><td>0</td><td>&quot;5.6.0.7&quot;</td><td>&quot;2020-10-26 06:10:50&quot;</td><td>null</td><td>null</td><td>&quot;newest&quot;</td><td>&quot;com.anydo&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌───────────┬───────────┬───────────┬───────────┬───┬───────────┬───────────┬───────────┬──────────┐\n",
       "│ reviewId  ┆ userName  ┆ userImage ┆ content   ┆ … ┆ replyCont ┆ repliedAt ┆ sortOrder ┆ appId    │\n",
       "│ ---       ┆ ---       ┆ ---       ┆ ---       ┆   ┆ ent       ┆ ---       ┆ ---       ┆ ---      │\n",
       "│ str       ┆ str       ┆ str       ┆ str       ┆   ┆ ---       ┆ str       ┆ str       ┆ str      │\n",
       "│           ┆           ┆           ┆           ┆   ┆ str       ┆           ┆           ┆          │\n",
       "╞═══════════╪═══════════╪═══════════╪═══════════╪═══╪═══════════╪═══════════╪═══════════╪══════════╡\n",
       "│ gp:AOqpTO ┆ Eric Tie  ┆ https://p ┆ I cannot  ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EhZuqSqqW ┆           ┆ lay-lh.go ┆ open the  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ naKRgv-9A ┆           ┆ ogleuserc ┆ app       ┆   ┆           ┆           ┆           ┆          │\n",
       "│ BYdajFUB0 ┆           ┆ ontent.co ┆ anymore   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WugPGh-SG ┆           ┆ m/a-/AOh1 ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ -fgH3…    ┆           ┆ 4GiGE…    ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ john      ┆ https://p ┆ I have    ┆ … ┆ Please    ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ H0WP4IQKB ┆ alpha     ┆ lay-lh.go ┆ been      ┆   ┆ note that ┆ 7         ┆           ┆ o        │\n",
       "│ Z2LrdNmFy ┆           ┆ ogleuserc ┆ begging   ┆   ┆ from      ┆ 15:05:52  ┆           ┆          │\n",
       "│ _YmpPCVrV ┆           ┆ ontent.co ┆ for a     ┆   ┆ checking  ┆           ┆           ┆          │\n",
       "│ 3diEU9KGm ┆           ┆ m/a-/AOh1 ┆ refund    ┆   ┆ our       ┆           ┆           ┆          │\n",
       "│ 3fAX6…    ┆           ┆ 4Gjpf…    ┆ from this ┆   ┆ records,  ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ app for…  ┆   ┆ your e…   ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Sudhakar  ┆ https://p ┆ Very      ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ EMCkJB8Iq ┆ .S        ┆ lay-lh.go ┆ costly    ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ 1p-r9dPwn ┆           ┆ ogleuserc ┆ for the   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ SYadA5BkP ┆           ┆ ontent.co ┆ premium   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ WTf32Z1az ┆           ┆ m/a-/AOh1 ┆ version   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ uuTvq…    ┆           ┆ 4GidH…    ┆ (approx   ┆   ┆           ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆ Indian…   ┆   ┆           ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ SKGflorid ┆ https://p ┆ Used to   ┆ … ┆ What do   ┆ 2020-10-2 ┆ newest    ┆ com.anyd │\n",
       "│ GFrUWuKGy ┆ a@bellsou ┆ lay-lh.go ┆ keep me   ┆   ┆ you find  ┆ 6         ┆           ┆ o        │\n",
       "│ cpje8kszj ┆ th.net    ┆ ogleuserc ┆ organized ┆   ┆ troubleso ┆ 14:58:29  ┆           ┆          │\n",
       "│ 3uwHN6tU_ ┆ DAVID S   ┆ ontent.co ┆ , but all ┆   ┆ me about  ┆           ┆           ┆          │\n",
       "│ fd4gLVFy9 ┆           ┆ m/-75aK0W ┆ the 2020  ┆   ┆ the       ┆           ┆           ┆          │\n",
       "│ z7hfG…    ┆           ┆ Fniac…    ┆ UPDATE…   ┆   ┆ update?   ┆           ┆           ┆          │\n",
       "│           ┆           ┆           ┆           ┆   ┆ We'…      ┆           ┆           ┆          │\n",
       "│ gp:AOqpTO ┆ Louann    ┆ https://p ┆ Dan       ┆ … ┆ null      ┆ null      ┆ newest    ┆ com.anyd │\n",
       "│ Hls7DW8wm ┆ Stoker    ┆ lay-lh.go ┆ Birthday  ┆   ┆           ┆           ┆           ┆ o        │\n",
       "│ DFzTkHwxu ┆           ┆ ogleuserc ┆ Oct 28    ┆   ┆           ┆           ┆           ┆          │\n",
       "│ qFkdNQtKH ┆           ┆ ontent.co ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ mO6Pt9jhZ ┆           ┆ m/-pBcY_Z ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "│ EQ0Q2…    ┆           ┆ -qfB4…    ┆           ┆   ┆           ┆           ┆           ┆          │\n",
       "└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import polars as pl\n",
    "\n",
    "df = pl.read_csv('../data/google_store_reviews.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>split</th></tr><tr><td>str</td><td>list[str]</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>[&quot;I&quot;, &quot;cannot&quot;, … &quot;anymore&quot;]</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>[&quot;I&quot;, &quot;have&quot;, … &quot;me&quot;]</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>[&quot;Very&quot;, &quot;costly&quot;, … &quot;better.&quot;]</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>[&quot;Used&quot;, &quot;to&quot;, … &quot;🤤🤤🤤&quot;]</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>[&quot;Dan&quot;, &quot;Birthday&quot;, … &quot;28&quot;]</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 2)\n",
       "┌─────────────────────────────────────────────────────┬─────────────────────────────────┐\n",
       "│ content                                             ┆ split                           │\n",
       "│ ---                                                 ┆ ---                             │\n",
       "│ str                                                 ┆ list[str]                       │\n",
       "╞═════════════════════════════════════════════════════╪═════════════════════════════════╡\n",
       "│ I cannot open the app anymore                       ┆ [\"I\", \"cannot\", … \"anymore\"]    │\n",
       "│ I have been begging for a refund from this app for… ┆ [\"I\", \"have\", … \"me\"]           │\n",
       "│ Very costly for the premium version (approx Indian… ┆ [\"Very\", \"costly\", … \"better.\"] │\n",
       "│ Used to keep me organized, but all the 2020 UPDATE… ┆ [\"Used\", \"to\", … \"🤤🤤🤤\"]      │\n",
       "│ Dan Birthday Oct 28                                 ┆ [\"Dan\", \"Birthday\", … \"28\"]     │\n",
       "└─────────────────────────────────────────────────────┴─────────────────────────────────┘"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content').str.split(by=' ').alias('split')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>content</th><th>splitn</th><th>split_exact</th></tr><tr><td>str</td><td>struct[10]</td><td>struct[11]</td></tr></thead><tbody><tr><td>&quot;I cannot open the app anymore&quot;</td><td>{&quot;I&quot;,&quot;cannot&quot;,&quot;open&quot;,&quot;the&quot;,&quot;app&quot;,&quot;anymore&quot;,null,null,null,null}</td><td>{&quot;I&quot;,&quot;cannot&quot;,&quot;open&quot;,&quot;the&quot;,&quot;app&quot;,&quot;anymore&quot;,null,null,null,null,null}</td></tr><tr><td>&quot;I have been begging for a refund from this app fo…</td><td>{&quot;I&quot;,&quot;have&quot;,&quot;been&quot;,&quot;begging&quot;,&quot;for&quot;,&quot;a&quot;,&quot;refund&quot;,&quot;from&quot;,&quot;this&quot;,&quot;app for over a month and nobody is replying me&quot;}</td><td>{&quot;I&quot;,&quot;have&quot;,&quot;been&quot;,&quot;begging&quot;,&quot;for&quot;,&quot;a&quot;,&quot;refund&quot;,&quot;from&quot;,&quot;this&quot;,&quot;app&quot;,&quot;for&quot;}</td></tr><tr><td>&quot;Very costly for the premium version (approx India…</td><td>{&quot;Very&quot;,&quot;costly&quot;,&quot;for&quot;,&quot;the&quot;,&quot;premium&quot;,&quot;version&quot;,&quot;(approx&quot;,&quot;Indian&quot;,&quot;Rupees&quot;,&quot;910 per year). Better to download the premium version of this app from apkmos website and use it. Microsoft to do list app is far more better.&quot;}</td><td>{&quot;Very&quot;,&quot;costly&quot;,&quot;for&quot;,&quot;the&quot;,&quot;premium&quot;,&quot;version&quot;,&quot;(approx&quot;,&quot;Indian&quot;,&quot;Rupees&quot;,&quot;910&quot;,&quot;per&quot;}</td></tr><tr><td>&quot;Used to keep me organized, but all the 2020 UPDAT…</td><td>{&quot;Used&quot;,&quot;to&quot;,&quot;keep&quot;,&quot;me&quot;,&quot;organized,&quot;,&quot;but&quot;,&quot;all&quot;,&quot;the&quot;,&quot;2020&quot;,&quot;UPDATES have made a mess of things !!! Y cudn&#x27;t u leave well enuf alone ??? Guess ur techies feel the need to keep making changes to justify continuing to collect their salary !!! 🤤🤤🤤&quot;}</td><td>{&quot;Used&quot;,&quot;to&quot;,&quot;keep&quot;,&quot;me&quot;,&quot;organized,&quot;,&quot;but&quot;,&quot;all&quot;,&quot;the&quot;,&quot;2020&quot;,&quot;UPDATES&quot;,&quot;have&quot;}</td></tr><tr><td>&quot;Dan Birthday Oct 28&quot;</td><td>{&quot;Dan&quot;,&quot;Birthday&quot;,&quot;Oct&quot;,&quot;28&quot;,null,null,null,null,null,null}</td><td>{&quot;Dan&quot;,&quot;Birthday&quot;,&quot;Oct&quot;,&quot;28&quot;,null,null,null,null,null,null,null}</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 3)\n",
       "┌────────────────────────────────┬────────────────────────────────┬────────────────────────────────┐\n",
       "│ content                        ┆ splitn                         ┆ split_exact                    │\n",
       "│ ---                            ┆ ---                            ┆ ---                            │\n",
       "│ str                            ┆ struct[10]                     ┆ struct[11]                     │\n",
       "╞════════════════════════════════╪════════════════════════════════╪════════════════════════════════╡\n",
       "│ I cannot open the app anymore  ┆ {\"I\",\"cannot\",\"open\",\"the\",\"ap ┆ {\"I\",\"cannot\",\"open\",\"the\",\"ap │\n",
       "│                                ┆ p\",\"anymore\",null,nu…          ┆ p\",\"anymore\",null,nu…          │\n",
       "│ I have been begging for a      ┆ {\"I\",\"have\",\"been\",\"begging\",\" ┆ {\"I\",\"have\",\"been\",\"begging\",\" │\n",
       "│ refund from this app for…      ┆ for\",\"a\",\"refund\",\"f…          ┆ for\",\"a\",\"refund\",\"f…          │\n",
       "│ Very costly for the premium    ┆ {\"Very\",\"costly\",\"for\",\"the\",\" ┆ {\"Very\",\"costly\",\"for\",\"the\",\" │\n",
       "│ version (approx Indian…        ┆ premium\",\"version\",\"…          ┆ premium\",\"version\",\"…          │\n",
       "│ Used to keep me organized, but ┆ {\"Used\",\"to\",\"keep\",\"me\",\"orga ┆ {\"Used\",\"to\",\"keep\",\"me\",\"orga │\n",
       "│ all the 2020 UPDATE…           ┆ nized,\",\"but\",\"all\",…          ┆ nized,\",\"but\",\"all\",…          │\n",
       "│ Dan Birthday Oct 28            ┆ {\"Dan\",\"Birthday\",\"Oct\",\"28\",n ┆ {\"Dan\",\"Birthday\",\"Oct\",\"28\",n │\n",
       "│                                ┆ ull,null,null,null,n…          ┆ ull,null,null,null,n…          │\n",
       "└────────────────────────────────┴────────────────────────────────┴────────────────────────────────┘"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    'content',\n",
    "    pl.col('content').str.splitn(by=' ', n=10).alias('splitn'),\n",
    "    pl.col('content').str.split_exact(by=' ', n=10).alias('split_exact')\n",
    ").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Concatenating strings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>colA</th><th>colB</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;a&quot;</td><td>&quot;aa&quot;</td></tr><tr><td>&quot;b&quot;</td><td>&quot;bb&quot;</td></tr><tr><td>&quot;c&quot;</td><td>&quot;cc&quot;</td></tr><tr><td>&quot;d&quot;</td><td>&quot;dd&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 2)\n",
       "┌──────┬──────┐\n",
       "│ colA ┆ colB │\n",
       "│ ---  ┆ ---  │\n",
       "│ str  ┆ str  │\n",
       "╞══════╪══════╡\n",
       "│ a    ┆ aa   │\n",
       "│ b    ┆ bb   │\n",
       "│ c    ┆ cc   │\n",
       "│ d    ┆ dd   │\n",
       "└──────┴──────┘"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.DataFrame(\n",
    "    {\n",
    "        'colA': ['a', 'b', 'c', 'd'], \n",
    "        'colB': ['aa', 'bb', 'cc', 'dd']\n",
    "    }\n",
    ")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>colA</th><th>colB</th><th>newColB</th></tr><tr><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;a&quot;</td><td>&quot;aa&quot;</td><td>&quot;aa new&quot;</td></tr><tr><td>&quot;b&quot;</td><td>&quot;bb&quot;</td><td>&quot;bb new&quot;</td></tr><tr><td>&quot;c&quot;</td><td>&quot;cc&quot;</td><td>&quot;cc new&quot;</td></tr><tr><td>&quot;d&quot;</td><td>&quot;dd&quot;</td><td>&quot;dd new&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 3)\n",
       "┌──────┬──────┬─────────┐\n",
       "│ colA ┆ colB ┆ newColB │\n",
       "│ ---  ┆ ---  ┆ ---     │\n",
       "│ str  ┆ str  ┆ str     │\n",
       "╞══════╪══════╪═════════╡\n",
       "│ a    ┆ aa   ┆ aa new  │\n",
       "│ b    ┆ bb   ┆ bb new  │\n",
       "│ c    ┆ cc   ┆ cc new  │\n",
       "│ d    ┆ dd   ┆ dd new  │\n",
       "└──────┴──────┴─────────┘"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    pl.all(),\n",
    "    (pl.col('colB') + ' new').alias('newColB')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 4)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>colA</th><th>colB</th><th>colC</th><th>col</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;a&quot;</td><td>&quot;aa&quot;</td><td>&quot;aaa&quot;</td><td>&quot;a &quot;</td></tr><tr><td>&quot;b&quot;</td><td>&quot;bb&quot;</td><td>&quot;bbb&quot;</td><td>&quot;b &quot;</td></tr><tr><td>&quot;c&quot;</td><td>&quot;cc&quot;</td><td>&quot;ccc&quot;</td><td>&quot;c &quot;</td></tr><tr><td>&quot;d&quot;</td><td>&quot;dd&quot;</td><td>&quot;ddd&quot;</td><td>&quot;d &quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 4)\n",
       "┌──────┬──────┬──────┬─────┐\n",
       "│ colA ┆ colB ┆ colC ┆ col │\n",
       "│ ---  ┆ ---  ┆ ---  ┆ --- │\n",
       "│ str  ┆ str  ┆ str  ┆ str │\n",
       "╞══════╪══════╪══════╪═════╡\n",
       "│ a    ┆ aa   ┆ aaa  ┆ a   │\n",
       "│ b    ┆ bb   ┆ bbb  ┆ b   │\n",
       "│ c    ┆ cc   ┆ ccc  ┆ c   │\n",
       "│ d    ┆ dd   ┆ ddd  ┆ d   │\n",
       "└──────┴──────┴──────┴─────┘"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    pl.all(),\n",
    "    (pl.col('colA') + pl.col('colB')).alias('colC')\n",
    "\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>colA</th><th>colB</th><th>newCol</th></tr><tr><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;a&quot;</td><td>&quot;aa&quot;</td><td>&quot;103:: ::a::aa&quot;</td></tr><tr><td>&quot;b&quot;</td><td>&quot;bb&quot;</td><td>&quot;103:: ::b::bb&quot;</td></tr><tr><td>&quot;c&quot;</td><td>&quot;cc&quot;</td><td>&quot;103:: ::c::cc&quot;</td></tr><tr><td>&quot;d&quot;</td><td>&quot;dd&quot;</td><td>&quot;103:: ::d::dd&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 3)\n",
       "┌──────┬──────┬───────────────┐\n",
       "│ colA ┆ colB ┆ newCol        │\n",
       "│ ---  ┆ ---  ┆ ---           │\n",
       "│ str  ┆ str  ┆ str           │\n",
       "╞══════╪══════╪═══════════════╡\n",
       "│ a    ┆ aa   ┆ 103:: ::a::aa │\n",
       "│ b    ┆ bb   ┆ 103:: ::b::bb │\n",
       "│ c    ┆ cc   ┆ 103:: ::c::cc │\n",
       "│ d    ┆ dd   ┆ 103:: ::d::dd │\n",
       "└──────┴──────┴───────────────┘"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    pl.all(),\n",
    "    pl.concat_str(\n",
    "        pl.lit(100)+3, \n",
    "        pl.lit(' '),\n",
    "        pl.col('colA'), \n",
    "        pl.col('colB'),\n",
    "        separator='::'\n",
    "    ).alias('newCol')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>colA</th><th>colB</th><th>concatenatedColA</th></tr><tr><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;a&quot;</td><td>&quot;aa&quot;</td><td>&quot;a, b, c, d&quot;</td></tr><tr><td>&quot;b&quot;</td><td>&quot;bb&quot;</td><td>&quot;a, b, c, d&quot;</td></tr><tr><td>&quot;c&quot;</td><td>&quot;cc&quot;</td><td>&quot;a, b, c, d&quot;</td></tr><tr><td>&quot;d&quot;</td><td>&quot;dd&quot;</td><td>&quot;a, b, c, d&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 3)\n",
       "┌──────┬──────┬──────────────────┐\n",
       "│ colA ┆ colB ┆ concatenatedColA │\n",
       "│ ---  ┆ ---  ┆ ---              │\n",
       "│ str  ┆ str  ┆ str              │\n",
       "╞══════╪══════╪══════════════════╡\n",
       "│ a    ┆ aa   ┆ a, b, c, d       │\n",
       "│ b    ┆ bb   ┆ a, b, c, d       │\n",
       "│ c    ┆ cc   ┆ a, b, c, d       │\n",
       "│ d    ┆ dd   ┆ a, b, c, d       │\n",
       "└──────┴──────┴──────────────────┘"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(\n",
    "    pl.all(),\n",
    "    pl.col('colA').str.join(delimiter=', ').alias('concatenatedColA')\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
